package com.cbb.lease.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cbb.lease.mapper.TypeMapper;
import com.cbb.lease.pojo.entity.Type;
import com.cbb.lease.service.TypeService;
import com.gsj.common.pojo.R;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: clms-eighth01
 * @description: 这是一个  实现接口类
 * @author: 陈斌斌
 * @create: 2021-07-24 14:23
 **/
@Service
public class TypeServiceImpl implements TypeService {

    @Resource
    private TypeMapper typeMapper;

    @Override
    public R getAllType() {
        List<Type> types = typeMapper.selectList(null);
        return R.ok().put("type",types);
    }

    @Override
    public R getAllTypePage(Integer currentPage, Integer pageSize, Type type) {
        Page<Type> page = new Page<>(currentPage,pageSize);
        QueryWrapper<Type> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(type.getTypeName())){queryWrapper.like("type_name",type.getTypeName());}
        Page<Type> typePage = typeMapper.selectPage(page, queryWrapper);
        return R.ok().put("records",typePage.getRecords()).put("total",typePage.getTotal());
    }

    @Override
    public R delById(Integer id) {
        int i = typeMapper.deleteById(id);
        return R.ok();
    }

    @Override
    public R updateType(Type type) {
        int i = typeMapper.updateById(type);
        return R.ok();
    }

    @Override
    public R addType(Type type) {
        int insert = typeMapper.insert(type);
        return R.ok();
    }
}
